package com.example.demo.config;

import com.example.demo.model.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@Slf4j
@ResponseBody
@ControllerAdvice
public class ErrorHandler {
    @ExceptionHandler
    public Result exception(Exception e){
        log.error("发生异常e{}",e);
        return Result.fail("内部错误");
    }
    @ExceptionHandler
    public Result exception(NullPointerException e){
        log.info("发生异常");
        return Result.fail("NullPointerException异常，请联系管理员");
    }
    @ExceptionHandler
    public Result exception(ArithmeticException e){
        log.info("发生异常");
        return Result.fail("ArithmeticException 异常，请联系管理员");
    }



}
